import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
import electron from "vite-plugin-electron";
import electronRenderer from "vite-plugin-electron-renderer"
import polyfillExports from "vite-plugin-electron-renderer"

const __dirname = path.resolve();

const pathResolve = (dir) => path.resolve(__dirname, dir);


// https://vitejs.dev/config/
export default ({mode}) =>{
    const env = loadEnv(mode,process.cwd())
    return defineConfig({
        base:mode == "development" ? "" : "./",
        plugins: [
            vue(),
            electron([{
                entry:"electron-main/index.ts",
            },{
                entry:"electron-preload/preload.ts",
            }]),
            electronRenderer(),
            polyfillExports(),
        ],
        resolve: {
            alias:{
                "@":pathResolve("./src")
            }
        },
        build: {
            emptyOutDir: false, // 默认情况下，若 outDir 在 root 目录下，则 Vite 会在构建时清空该目录
            outDir: "dist-electron"
        },
        css:{
          preprocessorOptions:{
              scss:{
                  additionalData:"@/assets/style/all.scss"
              }
          }
        },
        server:{
            //服务器代理
            proxy:{
                "^api":{
                    target: env.VITE_BACKEND_SERVER_URL ?? "http://localhost:8080",
                    secure:false,
                    changeOrigin:false
                }
            }
        }
    })
}
